package modelo.individuos;

import java.awt.Point;
import java.util.ArrayList;

import agentes.AgentInfoOptionPlace;

import modelo.Model;
import modelo.Model.Individuals;
import modelo.info.MapPoint;

public class Vehicle {

	private int x;
	private int y;
	private int roadDirection;
	private int position;
	private ArrayList<AgentInfoOptionPlace> lastPoints;
	private Model modelo;
	
	public Vehicle(Model model) {
	
		modelo = model;
		lastPoints = new ArrayList<AgentInfoOptionPlace>();
	}
	
	public void setPlace(int i,int j) {
		
		x = i;
		y = j;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getPosition() {
		return position;
	}

	public void setPosition(int position) {
		this.position = position;
	}
	
	public int getRoadDirection() {
		
		return roadDirection;
	}

	public void setRoadDirection(int direction) {
	
		roadDirection = direction;
	}
	
	public void takePlace() {
		
		modelo.getDriverMap()[x][y].setOcupante(Individuals.Vehiculo.ordinal());
	}
	
	public void freePlace() {

		modelo.getDriverMap()[x][y].setOcupante(Individuals.Libre.ordinal());
		
	}

	public ArrayList<AgentInfoOptionPlace> getLastPoints() {
		
		return lastPoints;
	}

	public void setLastPoints(ArrayList<AgentInfoOptionPlace> lastPoints) {
		
		this.lastPoints = lastPoints;
	}
	
	public String getTipoVia(Integer position) {
		
		return modelo.getDriverMap()[x][y].getDataList().get(position).getTipo();
	}
	
	public String getNombreVia(Integer position) {
		
		return modelo.getDriverMap()[x][y].getDataList().get(position).getNombre();
	}
	
	public int getNumPosibilidades() {
		
		return modelo.getDriverMap()[x][y].getDataList().size();
	}
	
	public void addPoint(AgentInfoOptionPlace place) {
		
		if (lastPoints.size() >= 2)
			lastPoints.remove(0);
		lastPoints.add(place);
	}

	public void updatePosition(int i, int j, int pos) {
		
		x = i;
		y = j;
		position = pos;
		roadDirection = modelo.getDriverMap()[x][y].getDataList().get(position).getSentido();
	}

	public boolean isOnMap() {
		
		return modelo.dentroMapa(x,y); 
	}
	
	public MapPoint actualPosition() {
		
		return modelo.getDriverMap()[x][y];
	}
}
